﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:Locator xmlns:vm="clr-namespace:c2iAzureSyncForDevelopper"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using SfdClient.ViewModel;


namespace SfdClient
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// In Silverlight and WPF, place the Locator in the App.xaml resources:
    /// </para>
    /// <code>
    /// &lt;Application.Resources&gt;
    ///     &lt;vm:Locator xmlns:vm="clr-namespace:c2iAzureSyncForDevelopper"
    ///                                  x:Key="Locator" /&gt;
    /// &lt;/Application.Resources&gt;
    /// </code>
    /// <para>
    /// Then use:
    /// </para>
    /// <code>
    /// DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
    /// </code>
    /// <para>
    /// You can also use Blend to do all this with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class Locator
    {
        /// <summary>
        /// Initializes a new instance of the Locator class.
        /// </summary>
        public Locator()
        {
            if (!ViewModelBase.IsInDesignModeStatic)
            {
                CreateLogsViewModel();
            }

        }

        #region AccountEditorViewModel
        private static AccountEditorViewModel _accountEditorViewModel;

        /// <summary>
        /// Gets the AccountEditorViewModel property.
        /// </summary>
        public static AccountEditorViewModel AccountEditorViewModelStatic
        {
            get
            {
                if (_accountEditorViewModel == null)
                {
                    CreateAccountEditorViewModel();
                }

                return _accountEditorViewModel;
            }
        }

        /// <summary>
        /// Gets the AccountEditorViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This non-static member is needed for data binding purposes.")]
        public AccountEditorViewModel AccountEditorViewModel
        {
            get
            {
                return AccountEditorViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the AccountEditorViewModel property.
        /// </summary>
        public static void CreateAccountEditorViewModel()
        {
            if (_accountEditorViewModel == null)
            {
                _accountEditorViewModel = new AccountEditorViewModel();
            }
        } 
        #endregion

        #region MainWindowViewModel
        private static MainWindowViewModel _mainWindowViewModel;

        /// <summary>
        /// Gets the MainWindowViewModel property.
        /// </summary>
        public static MainWindowViewModel MainWindowViewModelStatic
        {
            get
            {
                if (_mainWindowViewModel == null)
                {
                    CreateMainWindowViewModel();
                }

                return _mainWindowViewModel;
            }
        }

        /// <summary>
        /// Gets the AccountEditorViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This non-static member is needed for data binding purposes.")]
        public MainWindowViewModel MainWindowViewModel
        {
            get
            {
                return MainWindowViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the MainWindowViewModel property.
        /// </summary>
        public static void CreateMainWindowViewModel()
        {
            if (_mainWindowViewModel == null)
            {
                _mainWindowViewModel = new MainWindowViewModel();
            }
        }
        #endregion

        #region FolderBrowserViewModel

        private static FolderBrowserViewModel _folderBrowserViewModel;

        public FolderBrowserViewModel FolderBrowserViewModel
        {
            get { return FolderBrowserViewModelStatic; }
        }

        public static FolderBrowserViewModel FolderBrowserViewModelStatic
        {
            get
            {
                if (_folderBrowserViewModel == null)
                    _folderBrowserViewModel = new FolderBrowserViewModel();
                return _folderBrowserViewModel;
            }
        }

        #endregion

        #region AzureBrowserViewModel

        private static AzureBrowserViewModel _azureBrowserViewModel;

        public AzureBrowserViewModel AzureBrowserViewModel
        {
            get { return AzureBrowserViewModelStatic; }
        }

        public static AzureBrowserViewModel AzureBrowserViewModelStatic
        {
            get
            {
                if (_azureBrowserViewModel == null)
                    _azureBrowserViewModel = new AzureBrowserViewModel();
                return _azureBrowserViewModel;
            }
        }

        #endregion

        #region LogsViewModel

        private static LogsViewModel _logsViewModel;

        public LogsViewModel LogsViewModel
        {
            get { return _logsViewModel; }
        }

        public static LogsViewModel LogsViewModelStatic
        {
            get
            {
                if (_logsViewModel == null)
                    _logsViewModel = new LogsViewModel();
                return _logsViewModel;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the LogsViewModel property.
        /// </summary>
        public static void CreateLogsViewModel()
        {
            if (_logsViewModel == null)
            {
                _logsViewModel = new LogsViewModel();
            }
        } 

        #endregion

        #region AzureProjectsViewModel

        private static AzureProjectsViewModel _azureProjectsViewModel;

        public AzureProjectsViewModel AzureProjectsViewModel
        {
            get { return AzureProjectsViewModelStatic; }
        }

        public static AzureProjectsViewModel AzureProjectsViewModelStatic
        {
            get
            {
                if (_azureProjectsViewModel == null)
                    _azureProjectsViewModel = new AzureProjectsViewModel();
                return _azureProjectsViewModel;
            }
        }

        #endregion

        #region BrowserViewModel

        private static BrowserViewModel _browserViewModel;

        public BrowserViewModel BrowserViewModel
        {
            get { return BrowserViewModelStatic; }
        }

        public static BrowserViewModel BrowserViewModelStatic
        {
            get
            {
                if (_browserViewModel == null)
                    _browserViewModel = new BrowserViewModel();
                return _browserViewModel;
            }
        }

        #endregion

        #region SettingsViewModel

        private static SettingsViewModel _settingsViewModel;

        public SettingsViewModel SettingsViewModel
        {
            get { return SettingsViewModelStatic; }
        }

        public static SettingsViewModel SettingsViewModelStatic
        {
            get
            {
                if (_settingsViewModel == null)
                    _settingsViewModel = new SettingsViewModel();
                return _settingsViewModel;
            }
        }

        #endregion
    }
}